package fixtures;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import sgi.user.User;

import fit.ActionFixture;

public class LoginTest extends ActionFixture {
	
	private List<User> users= new ArrayList<User>();
	private User user = new User("");
	
	public LoginTest() //create demo users upon initialization
	{
		users.add(new User("Almog","12345",1,1));
		users.add(new User("Ofri","55555",1,0));
	}
	
	public void username(String username)
	{
		user.setUsername(username);
	}
	
	public void password(String password)
	{
		user.setPassword(password);
	}
	
	public boolean login() //go through users list, return true if the login details satisfy the login conditions.
	{
		Iterator<User> it = users.iterator();
		User CurrUser;
		while(it.hasNext())
		{
			CurrUser = (User) it.next();
			if(CurrUser.getUsername().equals(user.getUsername()) && CurrUser.getPassword().equals(user.getPassword()) && CurrUser.getOnlineStat() == 0)
				return true;
		}
		return false;
	}

}
